package com.quanshu.exchange.ui.gui.profile;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

public class DialogShare extends Dialog {

    @BindView(R.id.share_weChat)
    RelativeLayout shareWeChat;
    @BindView(R.id.share_friends)
    RelativeLayout shareFriends;
    @BindView(R.id.share_cancel)
    TextView shareCancel;

    private BehaviorSubject weChatSubject = BehaviorSubject.create();

    public BehaviorSubject getWeChatSubject() {
        return weChatSubject;
    }

    private BehaviorSubject friendsSubject = BehaviorSubject.create();

    public BehaviorSubject getFriendsSubject() {
        return friendsSubject;
    }


//    private BehaviorSubject cancelSubject = BehaviorSubject.create();
//    public BehaviorSubject getCancelSubject() {
//        return cancelSubject;
//    }

    public DialogShare(@NonNull Context context) {
        super(context, R.style.BaseDialog);
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.BottomAnim);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_share);
        ButterKnife.bind(this);

        initListener();
    }

    private void initListener() {

        RxViewHelper.getInstance().clicks(shareWeChat, o -> weChatSubject.onNext(o));//分享至微信

        RxViewHelper.getInstance().clicks(shareFriends, o -> friendsSubject.onNext(o));//分享至朋友圈

        RxViewHelper.getInstance().clicks(shareCancel, o -> dismiss());//取消分享
    }
}
